package com.tnovoselec.android.lbs.location;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class MyPositionOverlay extends Overlay {

	private final GeoPoint geoPoint;
	private final int resDrawableId;

	public MyPositionOverlay(GeoPoint geoPoint, int resDrawableId) {
		super();
		/* Don't check this time! */
		this.geoPoint = geoPoint;
		this.resDrawableId = resDrawableId;
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		if (!shadow) {
			Point point = new Point();
			mapView.getProjection().toPixels(geoPoint, point);

			Bitmap bitmap = BitmapFactory.decodeResource(mapView.getContext().getResources(), resDrawableId);
			drawBitmap(canvas, bitmap, point);
		}

		super.draw(canvas, mapView, shadow);
	}

	/**
	 * Can be easily overridden!
	 */
	protected void drawBitmap(Canvas canvas, Bitmap bitmap, Point point) {
		canvas.drawBitmap(bitmap, point.x - bitmap.getWidth() / 2, point.y - bitmap.getHeight() / 2, null);
	}

	@Override
	public boolean onTap(GeoPoint point, MapView mapView) {
		return false;
	}
}
